*** Settings ***
Documentation    TC04-Template Management FCL with Pushing Pricing
Resource    ../../Keywords/Common_Head.robot
Force Tags    P1
Metadata    Author    Momo
Metadata    ID    6850934


*** Test Cases ***
TC04-Template Management FCL with Pushing Pricing
    Step 1 User Goes To Basic Data Management Tender List
    Step 2 User Goes To Pricing Collaboration Pricing Project
    Step 3 Input Following Attributes
    Step 4 User Selects Row That Project Name Is Step 1 id FCL
    Step 5 In Pricing Project User Selects Row That Project Name
    Step 6 User Clicks Template Management Button
    Step 7 User Clicks Download Button
    Step 8 User Selects All The Optional Columns
    Step 9 User Clicks Start Button
    Step 10 Modify The Download File Fill All The Pricing Data In
    Step 11 User Clicks Upload Button In Step 3
    Step 12 User Select The Modified File
    Step 13 User Clicks Download File
    Step 14 User Clicks Start Button In Step4
    Step 15 In Step 1 Search
    Step 16 Select All Of Historical Tenders And Tariffs
    Step 17 Select Cheapest Rate
    Step 18 Download History And Check The Downloaded File
    Step 19 Click On Next Round Management Button
    Step 20 Download IPT Check The Values In Each Rate Column
    Step 21 Close This Dialog
    Step 22 Click On Close Button And yes In Pop up Window
    Step 23 User Goes To Basic Data Management Tender List 2



*** Keywords ***
Step ${step} User Goes To Basic Data Management Tender List
    #************************Step 1******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Click Create button
    #      Input with following attributes
    #      Tender ID some numbers such as step 1 id1435001 you can
    #     input with current datetime and some random number to
    #     avoid duplicate validation
    #      Tender Title some value such as Regression Test by
    #     Wendy001
    #      Customer 815 Miele
    #      Mode select all
    #      Level Global
    #      Click on Save button
    #  Expected:
    #      Created successfully with the message Tender has been
    #     added
    #************************************************************
    ${G_TENDERID}    Generate Tender ID
    ${TenderTitle}   Set Variable    Regression Test by auto
    Set Suite Variable     ${G_TENDERID}
    Login Space
    Create Tender    ${G_TENDERID}    ${TenderTitle}    815    true    true    true
    ${PROJECT}    Copy Dictionary    ${PROJECT_PARAM}
    Set To Dictionary    ${PROJECT}
    ...    TENDER_ID=${G_TENDERID}    TENDER_TITLE=${TenderTitle}    CUSTOEMR_NAME=Miele    CUSTOMER_LEVEL=Global
    ...   MODE=FCL    DEPUTY=SNOWLI01    TEMPLATE=${CURDIR}${/}TestData${/}FCLTemplate-Location-All.xlsx
    Set Suite Variable     ${PROJECT}

Step ${step} User Goes To Pricing Collaboration Pricing Project
    #************************Step 2******************************
    #  Do:
    #      User goes to Pricing Collaboration Pricing Project
    #      User clicks Create Project button
    #  Expected:
    #      A New Project dialog should be opened successfully
    #************************************************************
    Create Project    ${PROJECT}

Step ${step} Input Following Attributes
    #************************Step 3******************************
    #  Do:
    #      Input following attributes
    #      Tender ID step 1 id Regression
    #      Mode Air
    #      Deadline to TM current date 10 day
    #      Rate Validity From current date
    #      Rate Validity To current date 100 day
    #      Deputies NATZHANG
    #      Description for regression
    #      Click on Save button
    #  Expected:
    #      A new project is created successfully
    #************************************************************
    Log    Done in step 3

Step ${step} User Selects Row That Project Name Is Step 1 id FCL
    #************************Step 4******************************
    #  Do:
    #      User selects row that project name is step 1 id FCL
    #     Regression click on Data cleaning button
    #      Input following values
    #      Upload attachment
    #      Input following values
    #      User select map columns like that
    #      Origin Country country from D
    #      Destination Country country to G
    #      Origin City city from C
    #      Destination City city to F
    #      Origin State state from E
    #      Destination State state to H
    #      User clicks start button
    #  Expected:
    #      The summary shows successful
    #      Close this dialog
    #************************************************************
    Data Cleaning

Step ${step} In Pricing Project User Selects Row That Project Name
    #************************Step 5******************************
    #  Do:
    #      In Pricing Project user selects row that project name
    #     is step 1 id FCL Regression
    #  Expected:
    #      The row can be selected successfully
    #************************************************************
    Sleep    3
    Click    ${project_search_searchButton}
    Click    //td[contains(text(),"${G_TENDERID}")]

Step ${step} User Clicks Template Management Button
    #************************Step 6******************************
    #  Do:
    #      User clicks template management button
    #  Expected:
    #      A dialogue named step 1 id FCL Regression display
    #      There are three steps in this
    #      Step1 Confirm Data Cleaning Template download button is
    #     enabled
    #      Step2 Select and Define Optional Columns
    #      Step3 Generate Internal Pricing Template check button
    #     is checked in default
    #************************************************************
    Click    ${Project_toolbar_TemplateManagementButton}

Step ${step} User Clicks Download Button
    #************************Step 7******************************
    #  Do:
    #      User clicks download button
    #  Expected:
    #      1 The file named FCL_data_cleaning_template xlsx can
    #     download to local successfully
    #      2 Check all the values with actual condition
    #************************************************************
    ${file_path}    Get Download ZIP File Name    ${G_TENDERID}    .zip
    Should Contain    ${file_path}   ${G_TENDERID}-FCL-Regression Test by auto
    Set Test Variable    ${file_path}    ${file_path}

Step ${step} User Selects All The Optional Columns
    #************************Step 8******************************
    #  Do:
    #      User selects all the optional columns
    #      Input the TBN with some values
    #  Expected:
    #      The row can be selected successfully
    #************************************************************
    Check All Check Box for Dialog    Step2: Select and Define Optional Columns
    Click    ${Template_FCL_CustomerDataTab}
    Uncheck ALL TBN Checkbox    Step2: Select and Define Optional Columns
    Click    ${Template_FCL_CustomerDataTab}
    Fill Text    ((//label[contains(.,'TBN')])[1]/../div/div//input)[8]    222
    Select Options By   ((//label[contains(.,'TBN')])[1]/../div/div//SELECT)[3]    text    TEXT
    Click    ((//label[contains(.,'TBN')])[1]/../div/div//input)[7]

Step ${step} User Clicks Start Button
    #************************Step 9******************************
    #  Do:
    #      User clicks start button
    #  Expected:
    #      1 Just wait a few seconds and a progress bar will
    #     display After finish it the progress bar is disappeared
    #      2 A document named Internal Pricing Template 2018_ _ _
    #     _ _ will download and open automatically In this file
    #     the column Award
    #      Remarks exists
    #      3 Upload and Download buttons appear
    #      4 Summary shows successfully and also shows detail
    #     information in Internal Pricing Template
    #************************************************************
    ${filename}    Download File    ${Template_StartButton}
    Wait For Elements State    ${Template_UploadButton}    visible    30
    Wait For Elements State    ${Template_DownloadGeneratedTemplateButton}    visible    30
    Wait For Elements State    //*[.="Summary:"]    visible    30
    Set test Variable    ${filename}     ${filename} 

Step ${step} Modify The Download File Fill All The Pricing Data In
    #************************Step 10******************************
    #  Do:
    #      Modify the download file Fill all the pricing data in
    #     column Container Type under Ocean Freight Charges with
    #     value 20DC
    #  Expected:
    #      It can be modified successfully
    #************************************************************
    Open Excel Document    ${filename}    ${PROJECT.MODE}_D
    Write Excel Cell    5    146    20DC    ${PROJECT.MODE}_D
    Write Excel Cell    6    146    20DC    ${PROJECT.MODE}_D
    Write Excel Cell    5    46    ${EMPTY}    ${PROJECT.MODE}_D
    Write Excel Cell    5    47    ${EMPTY}    ${PROJECT.MODE}_D
    Write Excel Cell    6    46    ${EMPTY}    ${PROJECT.MODE}_D
    Write Excel Cell    6    47    ${EMPTY}    ${PROJECT.MODE}_D
    Save Excel Document   ${filename}
    Close All Excel Documents
    Reopen And Save Excel    ${filename}

Step ${step} User Clicks Upload Button In Step 3
    #************************Step 11******************************
    #  Do:
    #      User clicks upload button in step 3
    #  Expected:
    #      A dialogue named Upload Template display
    #************************************************************
    Click    ${Template_UploadButton}
    Wait For Elements State   ${upload_addFileButton}     enabled

Step ${step} User Select The Modified File
    #************************Step 12******************************
    #  Do:
    #      User select the modified file
    #  Expected:
    #      It upload successfully And it shows [2] lanes have been uploaded in your internal pricing template.
    #************************************************************
    Upload File By Selector    ${upload_addFileButton}    ${filename}
    Sleep    5
    Get Element States    //*[contains(text(), "[2] lanes have been uploaded in your internal pricing template.")]    contains    visible    enabled

Step ${step} User Clicks Download File
    #************************Step 13******************************
    #  Do:
    #      User clicks download file
    #  Expected:
    #      Check the data of the download file is the same with
    #     modified file
    #      Step 4 Start Skip button is displayed
    #************************************************************
    ${filename2}    Download File    css=[data-ng-click="downloadGeneratedTemplate()"]
    Open Excel Document    ${filename2}    ${PROJECT.MODE}_D
    Check Cell Value    5    146    20DC    ${PROJECT.MODE}_D
    Check Cell Value    6    146    20DC    ${PROJECT.MODE}_D
    Check Cell Value    5    46    None    ${PROJECT.MODE}_D
    Check Cell Value    5    47    None    ${PROJECT.MODE}_D
    Check Cell Value    6    46    None    ${PROJECT.MODE}_D
    Check Cell Value    6    47    None    ${PROJECT.MODE}_D
    Close All Excel Documents

Step ${step} User Clicks Start Button In Step4
    #************************Step 14******************************
    #  Do:
    #      User clicks Start button in step4
    #  Expected:
    #      A dialogue is displayed with project name
    #************************************************************
    click    css=[data-ng-click="startPushPricing()"]

Step ${step} In Step 1 Search
    #************************Step 15******************************
    #  Do:
    #      In Step 1 Search
    #      Rates valid from 2020 01 01
    #      Click on Next
    #  Expected:
    #      Steps 2 Tenders Tariffs is displayed
    #************************************************************
    fill text    //input[@name="validFrom"]    01/01/2020
    click    [data-ng-click="toStepTwo()"]

Step ${step} Select All Of Historical Tenders And Tariffs
    #************************Step 16******************************
    #  Do:
    #      Select All of Historical Tenders and Tariffs
    #      Click on Next
    #  Expected:
    #      Step 3 Lane Setting is displayed
    #************************************************************
    click    css=[data-ng-click="add(activeAvailableItems)"]
    click    css=[data-ng-click="toThree()"]

Step ${step} Select Cheapest Rate
    #************************Step 17******************************
    #  Do:
    #      Select Cheapest Rate
    #      Click on Next
    #  Expected:
    #      Step 4 View Results is displayed
    #      Download History and Download IPT buttons are enable
    #      List of results are displayed with columns Tender Name
    #     Pricing Lead Date Time of Push Pricing and Hit Ratio of
    #     Push Pricing
    #      Close Previous and Next Round Management buttons are
    #     enable
    #************************************************************
    Click    css=[data-ng-model="selectRateLevel.cheapest"]
    Click    css=[data-ng-disabled="isNextFour()"]
    Wait Until Search Finished

Step ${step} Download History And Check The Downloaded File
    #************************Step 18******************************
    #  Do:
    #      Download History and check the downloaded file
    #      Download IPT and check the downloaded file
    #  Expected:
    #      History file contains project name in some rate columns
    #      IPT file contains the pricing in some rate columns
    #************************************************************
    Wait Until Keyword Succeeds    30    3    Click    (//td[contains(text(),'${G_TENDERID}')])[1]
    Get Text    //td[contains(text(),'${G_TENDERID}')]/../td[4]    >    0
    ${History}    Download File    css=[data-ng-disabled="downloadHisAble()"]
    Open Excel Document    ${History}     ${PROJECT.MODE}_D
    ${row5}    Read Excel Row    5
    Should Contain    ${row5}    ${G_TENDERID}
    ${row6}    Read Excel Row    6
    Should Contain    ${row6}    ${G_TENDERID}
    Close All Excel Documents
    ${IPT}    Download File    css=[data-ng-disabled="downloadIPTAble()"]
    Open Excel Document    ${IPT}     ${PROJECT.MODE}_D
    ${COL1}    Read Excel Row    3
    Close All Excel Documents
    Set Test Variable    ${COL1}    ${COL1}

Step ${step} Click On Next Round Management Button
    #************************Step 19******************************
    #  Do:
    #      Click on Next Round Management button
    #  Expected:
    #      Round management dialog is displayed
    #************************************************************
    Click    css=[data-ng-if="isNextRoundShow()"]

Step ${step} Download IPT Check The Values In Each Rate Column
    #************************Step 20******************************
    #  Do:
    #      Download IPT check the values in each rate column
    #  Expected:
    #      Should be the same as Step 18
    #************************************************************
    ${IPT2}    Download File    css=[data-ng-click="downloadInternalTemplate()"]
    Open Excel Document    ${IPT2}     ${PROJECT.MODE}_D
    ${COL2}    Read Excel Row    3
    Close All Excel Documents
    Should Be Equal    ${COL2}    ${COL1}

Step ${step} Close This Dialog
    #************************Step 21******************************
    #  Do:
    #      Close this dialog
    #      Go back to Pricing Project
    #      Select the current project click on Data Cleaning click
    #     yes in pop up window
    #  Expected:
    #      Data Cleaning dialog is displayed
    #************************************************************
    CLICK    css=[data-ng-click="closeRoundPage()"]

Step ${step} Click On Close Button And yes In Pop up Window
    #************************Step 22******************************
    #  Do:
    #      Click on Close button and yes in pop up window
    #      Click on Search in Pricing Project
    #      Select the current project click on Delete Project and
    #     yes in pop up windown
    #  Expected:
    #      The project is deleted successfully
    #************************************************************
    Delete Project    ${G_TENDERID}

Step ${step} User Goes To Basic Data Management Tender List 2
    #************************Step 23******************************
    #  Do:
    #      User goes to Basic Data Management Tender List
    #      Search out the tender created in step1
    #      Click on Delete button
    #      Click on Yes button in the popup dialog
    #  Expected:
    #      System displays Tender has been deleted
    #************************************************************
    Delete Tender    ${G_TENDERID}
